import { isString } from '@/hooks/useType'

export const getUploadFiles = (files: any[] | null | undefined) => {
  if (files) {
    return files.map((item) => {
      if (item.response) {
        if (item.response.code == 200) {
          return item.response.data[0].path
        } else {
          return ''
        }
      } else {
        return item.url ? item.url.replace(import.meta.env.BUTTERFLY_BASE_API_URL, '') : ''
      }
    })
  }
  return []
}

export const transformToUploadFileList = (files: string | string[]) => {
  if (isString(files)) {
    return files === '' ? [] : [{ url: files, status: 'finished' }]
  }
  return (files as string[]).map((item) => ({ url: item, status: 'finished' }))
}
